export function Methods () {
    this.routers = {};
    this.path = "";
};

Methods.prototype = {
    init:function() {
        let self = this;
        window.onhashchange = function () {
            self.changeUrl();
        };
        window.onload = function () {
            self.changeUrl();
        };
    },
    map:function(path,callback){
        let self = this;
        if(callback&&typeof callback === "function"){
            self.routers[path] = {
                callback:callback,
                fn:null
            }
        }else{
            console.log("参数有问题");
        }
    },
    changeUrl:function(){
        let self = this;
        let path = location.hash.split("#")[1];
        if(this.routers[path]){
            self.path = path;
            self.routers[path].callback();
        }else{
            location.hash = "/index";
        }
    },
    asyncFun:function(callback) {
        let self = this;
        if(self.routers[self.path].fn){
            self.routers[self.path].fn.renderHTML();
            self.routers[self.path].fn.onEvents();
        }else{
            this.routers[self.path].fn = new callback();
            // this.routers[self.path].fn;
        }
    }
};

